<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="/static/css/reset.css">
    <link rel="stylesheet" href="/static/css/index.css">
    <style>
        html,
        body {
            width: 100%;
            height: 100%
        }

        .fr {
            float: right;
        }

        .w100 {
            width: 100%;
        }

        .h100 {
            height: 100%;
        }

        .bc {
            background-color: rgb(84, 92, 100);
        }

        .el-header {
            padding: 0;
        }
    </style>
</head>

<body>
    <div id="app">

        <el-row>
            <el-button type="primary" @click="showDialog">添加管理员</el-button>
        </el-row>
        <el-tabs v-model="activeName" @tab-click="handleClick">
            <el-table :data="tableData" style="width: 100%" max-height="600">
                <el-table-column fixed prop="id" label="id" width="150">
                </el-table-column>
                <el-table-column prop="nickname" label="姓名" width="100">
                </el-table-column>
                <el-table-column prop="username" label="用户名" width="150">
                </el-table-column>
                <el-table-column prop="level" label="权限级别" width="100">
                </el-table-column>
                <el-table-column prop="ip" label="上次登录ip" width="200">
                </el-table-column>
                <el-table-column prop="content" label="备注" >
                </el-table-column>
                <el-table-column fixed="right" label="操作">
                    <template slot-scope="scope">
                        <el-button @click.native.prevent="deleteRow(scope.$index, tableData4)" type="text" size="small">
                            编辑
                        </el-button>
                        <el-button @click.native.prevent="deleteRow(scope.$index, tableData4)" type="text" size="small">
                            移除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-tabs>
        <el-dialog title="新增管理员" :visible.sync="dialogFormVisible">
            <el-form :model="form">
                <el-form-item label="账号" :label-width="formLabelWidth">
                    <el-input v-model="form.username" auto-complete="off"></el-input>
                </el-form-item>
                <el-form-item label="密码" :label-width="formLabelWidth">
                    <el-input type="password" v-model="form.password" auto-complete="off"></el-input>
                </el-form-item>
                <el-form-item label="权限等级" :label-width="formLabelWidth">
                    <el-select v-model="form.level" placeholder="级别越高权限越高">
                        <el-option label="会员" value="16"></el-option>
                        <el-option label="管理员" value="32"></el-option>
                        <el-option label="总管理员" value="64"></el-option>
                        <el-option label="超级管理员" value="128"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="姓名" :label-width="formLabelWidth">
                    <el-input v-model="form.nickname" auto-complete="off"></el-input>
                </el-form-item>
                <el-form-item label="手机" :label-width="formLabelWidth">
                    <el-input v-model="form.phone" auto-complete="off"></el-input>
                </el-form-item>
                <el-form-item label="备注" :label-width="formLabelWidth">
                    <el-input type="textarea" v-model="form.content"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="addAdmin">确 定</el-button>
            </div>
        </el-dialog>
    </div>

</body>
<script src="/static/js/dbkj.js"></script>
<script src="/static/js/vue.js"></script>
<!-- 引入组件库 -->
<script src="/static/js/index.js"></script>
<script src="/static/js/axios.js"></script>
<script>
    var app = new Vue({
        el: "#app",
        mounted(){
            this.loadData();
        },
        data() {
            return {
                activeName: 'first',
                form: {
                    username: "",
                    password: "",
                    level: "",
                    nickname: "",
                    phone: "",
                    content: ""
                },
                tableData: [{
                    id: '1',
                    nickname: '王小虎',
                    username: '上海',
                    level:"会员",
                    content: '一个小会员',
                    ip:"182.123.123.123",
                }],
                dialogFormVisible: false,
                formLabelWidth: '120px',
                dialogImageUrl: '',
                dialogVisible: false
            }
        },
        methods: {
            loadData(){
                this.getAdmin();
            },
            showDialog() {
                this.dialogFormVisible = !this.dialogFormVisible;
            },
            // 切换事件
            handleClick() {

            },
            handleRemove(file, fileList) {
                console.log(file, fileList);
            },
            handlePictureCardPreview(file) {
                this.dialogImageUrl = file.url;
                this.dialogVisible = true;
            },
            //获取管理员
            getAdmin(){
                let _this = this;
                axios.get('get_admin')
                    .then(res=>{
                        console.log(res);
                        _this.tableData = res.data;
                    })
                    .catch(err=>{

                    })
            },
            //添加管理员
            addAdmin(){
                let data = this.form;
                let _this = this;
                axios.post('add_admin',data)
                    .then(res=>{
                        _this.dialogVisible = true;
                        _this.$message({
                            message: res.data.msg,
                            type: 'success'
                        });
                        _this.dialogVisible = false;
                    })
                    .catch(err=>{
                        _this.$message({
                            message: err.data.msg,
                            type: 'error'
                        });
                    })
            }
        }
    })
</script>

</html>